﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace AI.Steering
{
    /// <summary>
    /// 离开
    /// </summary>
    public class SteeringForFlee : Steering
    {
        [Tooltip("目标物体变换组件")]
        public Transform targetTF;
        [Tooltip("最小距离")]
        public float minDistance = 3;
        public override Vector3 GetForce()
        {
            //自身与目标间距 过小
            Vector3 fromTarget = transform.position - targetTF.position;
            if (fromTarget.magnitude < minDistance)
            {
                //期望力 = 自身点 - 目标点
                Vector3 expectForce = fromTarget.normalized * speed;
                //实际力 = 期望力 - 当前力
                return (expectForce - controller.currentForce) * weight;//权重越大，实际力越大
            }
            return Vector3.zero;
        }
    }
}

